package app.fugema.shop.main.center.vm;

import android.app.Application;

import com.base.common.netBeanPackage.BaseApiResult;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.viewmodel.BaseViewModel;
import app.fugema.shop.http.HttpService;
import app.fugema.shop.http.SuccessResult;
import app.fugema.shop.main.center.model.BalanceDetailResult;
import app.fugema.shop.main.center.model.BalanceResult;
import app.fugema.shop.main.center.model.CheckMethodResult;
import app.fugema.shop.main.center.model.CollectGoodsResult;
import app.fugema.shop.main.center.model.CollectShopResult;
import app.fugema.shop.main.center.model.CouponListResult;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import app.fugema.shop.main.order.model.PaymentResult;
import app.fugema.shop.main.order.vm.OrderConfirmVN;
import app.fugema.shop.main.wallet.model.PayInfoResult;

public class UserVM extends BaseViewModel
{

    private OrderConfirmVN paymentVm;

    public UserVM(@NonNull Application application)
    {
        super(application);
        paymentVm = new OrderConfirmVN(application);
        addBaseViewModel(paymentVm);
    }

    /**
     * 查询 用户余额
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BalanceResult>> getUserMoney(String userkey)
    {
        return send(HttpService.getHttpServer().userMoney(userkey));
    }

    /**
     * 查询 用户余额 明细
     * @param pageNo
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BalanceDetailResult>> getUserMoneyDetail(int pageNo, String userkey)
    {
        return send(HttpService.getHttpServer().userMoneyDetail(pageNo, 15,userkey));
    }


    /**
     *  查询 优惠券列表
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CouponListResult>> getUserCounponList(String userkey)
    {
        return send(HttpService.getHttpServer().getUserCounponList(userkey));
    }

    /**
     * 查询收藏的商品
     * @param page
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CollectGoodsResult>> getCollectionProduct(int page, String userkey)
    {
        Map<String,Object> params = new HashMap<>();
        //pageno=1&pagesize=10&userkey=Zit
        params.put("pageno",page);
        params.put("pagesize",10);
        params.put("userkey",userkey);
        return send(HttpService.getHttpServer().getCollectionProduct(params));
    }

    /**
     * 查询收藏的店铺
     * @param page
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CollectShopResult>> getCollectionShop(int page, String userkey)
    {
        Map<String,Object> params = new HashMap<>();
        //pageno=1&pagesize=10&userkey=Zit
        params.put("pageno",page);
        params.put("pagesize",10);
        params.put("userkey",userkey);
        return send(HttpService.getHttpServer().getCollectionShop(params));
    }

    /**
     *  取消收藏商品
     * @param productId
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> cancelCollectProduct(long productId, String userkey)
    {
        return send(HttpService.getHttpServer().cancelCollectProduct(productId,userkey));
    }

    /**
     *  取消收藏店铺
     * @param shopId
     * @param userkey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> cancelCollectShop(long shopId, String userkey)
    {
        return send(HttpService.getHttpServer().cancelCollectShop(shopId,userkey));
    }

    /**
     *  获取充值方式
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<PaymentResult>> enablePaymentList(String userKey)
    {
        return send(HttpService.getHttpServer().enablePaymentList(userKey));
    }

    /**
     *  是否设置支付密码
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<SuccessResult>> isSetPayPwd(String userKey)
    {
        return send(HttpService.getHttpServer().isSetPayPwd(userKey));
    }

    /**
     *  充值 获取付款信息
     * @param typeid
     * @param money
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<PayInfoResult>> chargeMoney(String typeid,Double money,String userKey)
    {
        return send(HttpService.getHttpServer().chargeMoney(typeid,money,userKey));
    }
    /**
     *  设置 支付密码
     * @param pwd
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> setPayPwd(String pwd,String userKey)
    {
        return send(HttpService.getHttpServer().setPayPwd(pwd, userKey));
    }

    /**
     *  检查支持提现的支付方式
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<CheckMethodResult>> checkTiXianMethod(String userKey)
    {
        return send(HttpService.getHttpServer().checkTiXianMethod( userKey));
    }

    /**
     *  提交提现 申请
     * @param openid
     * @param amount
     * @param nickname
     * @param pwd
     * @param applytype
     * @param userKey
     * @return
     */
    public MutableLiveData<LiveDataWrapper<BaseApiResult>> appleyDarwMoney(String openid,int amount,String nickname,String pwd,int applytype,String userKey)
    {
        Map<String,Object> applyParams = new HashMap<>();
        /*
        openid shamoshuisheng@aliyun.com
        nickname 杜延平
        amount 1
        pwd 123456
        applytype 3
        userkey ZitrK
                */
        applyParams.put("openid",openid);
        applyParams.put("nickname",nickname);
        applyParams.put("amount",amount);
        applyParams.put("pwd",pwd);
        applyParams.put("applytype",applytype);
        applyParams.put("userkey",userKey);

        return send(HttpService.getHttpServer().appleyDarwMoney( applyParams));
    }

}
